package lib.persistence.commands;

import java.sql.Connection;
import java.sql.SQLException;

public class DeleteRow extends CommandAbstract
{
	private Connection conn;

	public DeleteRow(Connection conn)
	{
		this.conn = conn;
	}
	public DeleteRow()
	{
		this.conn = global.ConnectionManager.getInstance().getConnection();
	}

	public boolean execute(int id, String tableName) throws SQLException {
 		return executeWhereInt("id", tableName, id);
	}
	public boolean executeWhereInt(String columnName, String tableName, int columnValue) throws SQLException {

		String cmd = String.format("DELETE FROM `%s` WHERE %s = %d",tableName,columnName, columnValue);
		System.out.println(cmd);
		boolean out = conn.prepareStatement(cmd).execute();
		return out;
		
	}
	public boolean executeCustomWhere(String tableName, String customWhere) throws SQLException 
	{
		String cmd = String.format("DELETE FROM `%s` WHERE %s",tableName, customWhere);
		System.out.println(cmd);
		return conn.prepareStatement(cmd).execute();
	
	}
}
